package cn.wubo.one.table.ai.config;

import cn.wubo.entity.sql.web.EntityWebService;
import cn.wubo.one.table.ai.OneTableAiProperties;
import cn.wubo.one.table.ai.service.IOneTableAiService;
import cn.wubo.one.table.ai.service.impl.OneTableAiServiceImpl;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({OneTableAiProperties.class})
public class OneTableAiConfiguration {

    @Bean
    public ChatClient chatClient(ChatModel chatModel) {
        ChatClient.Builder builder = ChatClient.builder(chatModel)
                .defaultAdvisors(
                SimpleLoggerAdvisor.builder().build() // logger advisor
        );
        return builder.build();
    }

    @Bean
    public IOneTableAiService oneTableAiService(ChatClient chatClient, EntityWebService entityWebService, OneTableAiProperties properties) {
        return new OneTableAiServiceImpl(chatClient, entityWebService, properties);
    }
}
